-----------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/juanpablouribetrujillo/My Drive (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analys
> is/Resurfacing_events.log
  log type:  text
 opened on:  24 Jun 2024, 22:25:23

. *Define selected outcomes ;
.  global var_outcomes iri sn_d urban
>                                                         aadt_10000
>                                                         pavement_thickness
>                                                         
> ;

.                                         ;
. global more_var  Dcat_surface_cat surface_cat surface_type      average_grade_seg                       
>                                                         pavement_section truck_route
>                                                         sh_h20_10m_s sh_urb_10m_s sh_elev_10m_s sh_sd_ele
> v_10m_s sh_temp_10m_s sh_precip_10m_s 
>                                                         multiple_id_1998_before
>                                                         ;

.                 use "../data/hpms_hwy_stats_88_08.dta", clear  ;

. do "_setup_expenditure.do";

. /******************************************************************
> 
> setup_expenditure.do
> 
> Subroutine to calculate expenditure variables for all analysis programs;
> 
> mt 20190506
> *******************************************************************/
. # delim ;  
delimiter now ;
. * expenditure on length and IRI from SF12a. Check that categories are right. Can we break apart ROW?;
. *conversion factor to get to 10^6 2010 dollars;
. gen deflate= 1/(ppiaco_2010*10);

. *gen deflate= 1;
. *consolidate rural and urban SF12a variables that we need;
. local rur_urb_list      "exp_eng_row_IH                 exp_row_IH              exp_eng_IH              e
> xp_new_cons_IH
>                         exp_relocation_IH               exp_recons_IH           exp_recons_add_IH       e
> xp_recons_noadd_IH
>                         exp_maj_wide_IH                 exp_R3_IH               exp_R3_min_wide_IH      e
> xp_R3_rehab_rest_IH    
>                         exp_R3_resurf_IH
>                         exp_new_bridge_IH exp_bridgereplacement_IH exp_majorbridgerehab_IH exp_minorbridg
> erehab_IH exp_bridge_IH
>                         ";

. foreach exp_var of local rur_urb_list{;
  2.                 replace `exp_var'_urban=cond(`exp_var'_urban==.,0,`exp_var'_urban);
  3.                 replace `exp_var'_rural=cond(`exp_var'_rural==.,0,`exp_var'_rural);
  4.                 gen `exp_var'_all = `exp_var'_urban + `exp_var'_rural;
  5.                 drop `exp_var'_urban `exp_var'_rural;
  6.                 };
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)

. *consolidate SF12a variables into nominal construction and resurfacing for pre and post 1998;
. *NB: exp_new_cons_IH_all and exp_maj_wide_IH_all are common to pre and post 1998 construction;
. gen exp_L_IH_SF12a_n_old=       exp_eng_row_IH_all + exp_new_cons_IH_all + exp_maj_wide_IH_all;

. gen exp_IRI_IH_SF12a_n_old=     exp_recons_IH_all  + exp_R3_IH_all;

.  gen exp_L_IH_SF12a_n_new=      exp_row_IH_all     + exp_eng_IH_all      + exp_new_cons_IH_all  + exp_rel
> ocation_IH_all + exp_maj_wide_IH_all;

.                         gen exp_IRI_IH_SF12a_n_new=     exp_recons_add_IH  + exp_recons_noadd_IH + exp_R3
> _min_wide_IH   + exp_R3_rehab_rest_IH  + exp_R3_resurf_IH;

. * Do the same for bridge expenditure ;
. gen exp_bridge_IH_SF12a_n_new=cond( year>1998,
>                                                                         exp_new_bridge_IH_all+exp_bridger
> eplacement_IH_all+exp_majorbridgerehab_IH_all+exp_minorbridgerehab_IH_all,.);
(147,240 missing values generated)

.                                                                         gen exp_bridge_IH_SF12a_n_old=con
> d( year<=1998,
>                                                                         exp_bridge_IH_all,.);
(160,858 missing values generated)

. *diagnostics -- should all be zero -- this test won't work for construction;
. sum exp_IRI_IH_SF12a_n_new exp_IRI_IH_SF12a_n_old if year>1998;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
exp_IRI_IH~w |    160,858    220065.6      226117          0    1142287
exp_IRI_IH~d |    160,858           0           0          0          0

. sum exp_IRI_IH_SF12a_n_new exp_IRI_IH_SF12a_n_old if year<=1998;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
exp_IRI_IH~w |    147,240           0           0          0          0
exp_IRI_IH~d |    147,240      107408      108656          0     560136

. *consolidate pre and post 1998 variable construction;
. gen exp_IRI_IH_SF12a_n =        cond(year>1998, exp_IRI_IH_SF12a_n_new, exp_IRI_IH_SF12a_n_old);

. gen exp_L_IH_SF12a_n =          cond(year>1998, exp_L_IH_SF12a_n_new, exp_L_IH_SF12a_n_old);

. gen exp_bridge_IH_SF12a_n =             cond(year>1998, exp_bridge_IH_SF12a_n_new, exp_bridge_IH_SF12a_n_
> old);

. *clean up -- save reloacation;
. gen temp = exp_relocation_IH_all;

. gen temp2 =exp_row_IH_all ;

. foreach exp_var of local rur_urb_list{;
  2.                 drop `exp_var'_all;
  3.                 };

.                 drop *_new *_old;

. rename temp exp_relocation_IH_all_n;

.  rename temp2 exp_row_IH_all_n ;

. *calculate total IH and SF12a maintenance;
. gen exp_IH_total_SF12_n = exp_IH_mtn_all + exp_IH_k_all;
(351 missing values generated)

. gen exp_IH_mtn_SF12a_n = exp_IH_total_SF12_n - exp_IRI_IH_SF12a_n - exp_L_IH_SF12a_n -exp_bridge_IH_SF12a
> _n;
(351 missing values generated)

. sum exp_IH_mtn_SF12a_n, d ;

                     exp_IH_mtn_SF12a_n
-------------------------------------------------------------
      Percentiles      Smallest
 1%       -73065        -796329
 5%         4228        -796329
10%     7764.049        -796329       Obs             307,747
25%        19215        -796329       Sum of wgt.     307,747

50%        48833                      Mean           75766.26
                        Largest       Std. dev.      104646.2
75%     100944.5        2017193
90%     181282.9        2062267       Variance       1.10e+10
95%     237426.6        3278198       Skewness       2.799105
99%       458010        3303381       Kurtosis       40.18784

. replace exp_IH_mtn_SF12a_n= cond(exp_IH_mtn_SF12a_n<0,0,exp_IH_mtn_SF12a_n );
(5,948 real changes made)

. sum exp_IH_mtn_SF12a_n, d ;

                     exp_IH_mtn_SF12a_n
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%         4228              0
10%     7764.049              0       Obs             307,747
25%        19215              0       Sum of wgt.     307,747

50%        48833                      Mean            78426.6
                        Largest       Std. dev.      97296.26
75%     100944.5        2017193
90%     181282.9        2062267       Variance       9.47e+09
95%     237426.6        3278198       Skewness       4.440624
99%       458010        3303381       Kurtosis       45.17407

. ;
. *convert to real 2010 USD 10^6;
. *NB: deflate calculated in calling program;
. rename app_IH app_IH_n;

. rename exp_IH_mtn_all exp_IH_mtn_SF12_n;

. ren rev_grand_total_mt rev_grand_total_mt_n;

. ren rev_total_h rev_total_h_n;

. ren rev_total_mt rev_total_mt_n ;

. ren rev_total_m_fuel_h rev_total_m_fuel_h_n ;

. local real_list "exp_IH_total_SF12 exp_IH_mtn_SF12a exp_IRI_IH_SF12a exp_L_IH_SF12a app_IH exp_IH_mtn_SF1
> 2 exp_relocation_IH_all 
>                                  rev_grand_total_mt rev_total_h rev_total_mt rev_total_m_fuel_h
>                                  exp_bridge_IH_SF12a exp_row_IH_all
>                                  ";

. foreach exp_var of local real_list{;
  2.                 gen `exp_var'_r=deflate*`exp_var'_n;
  3.                 drop `exp_var'_n;
  4.                 };
(351 missing values generated)
(351 missing values generated)
(77,386 missing values generated)
(351 missing values generated)
(105,706 missing values generated)
(399 missing values generated)
(105,706 missing values generated)
(399 missing values generated)

.         forvalues i=1(1)5{;
  2.                                 gen deflate_L`i'= 1/(ppiaco_2010_L`i'*10);
  3.                 ren L`i'FHWA_apport_LW L`i'FHWA_apport_LW_n;
  4.                 gen L`i'FHWA_apport_LW_r=deflate_L`i'*L`i'FHWA_apport_LW_n;
  5.                 drop L`i'FHWA_apport_LW_n;
  6. };
(303 missing values generated)
(351 missing values generated)
(399 missing values generated)
(447 missing values generated)
(495 missing values generated)

.                                                 *label and drop superflous expenditure data;
. label var       exp_IH_total_SF12_r     "Total IH exp SF12 real";

. label var       exp_IH_mtn_SF12_r       "Total IH maint exp SF12 real";

. label var       exp_IH_mtn_SF12a_r      "Total IH maint exp SF12a real";

.  label var      exp_IRI_IH_SF12a_r      "Total IH IRI exp SF12a real";

.  label var      exp_L_IH_SF12a_r        "Total IH L exp SF12a real";

. label var       app_IH_r                "Total IH approp real";

. label var       exp_relocation_IH_all   "Total IH exp relocation, >1998";

. label var   rev_grand_total_mt_r          "Total revenue mass transit account real [source: FE9 p2 ]";

. label var   rev_total_mt_r        "Total revenue highway and mass transit account real [source: FE9 p2 ]"
> ;

. label var   rev_total_h  "Total revenue highway account real [source: FE9 p2 ]";

. label var rev_total_m_fuel_h                     "Total Revenue motor fuel  (Highway motor fuel) [source:
>  FE9 p1 ]";

.         *drop exp_IH_k_rural-exp_subtotal_mtn_urban;
. exit;

end of do-file

. do "_cleaning_and_new_variables_sample.do";

. # d ;
delimiter now ;
. *label variables to mathc the names in the tables ;
. label var exp_L_IH_SF12a_r "\( Y^L \)";

. label var  exp_IRI_IH_SF12a_r "\( Y^L\:in\:IRI \)";

. label var  exp_IH_mtn_SF12a_r "\( Y^L\: in\: Maint.\)";

. ****************************************************;
. *calculate differences in miles and IRI;
. *local D_vars "u_iri_IH u_iri_urban u_iri_rural u_lane_miles_IH u_lane_miles_rural u_lane_miles_urban";
. local D_vars iri ;

. sort state id year ;

. foreach varname of local D_vars{;
  2.         *changed from leads to lags, 20190429;
.         gen D`varname'=cond(
>                         id[_n]==id[_n-1]&
>                         state[_n]==state[_n-1]&
>                         `varname'[_n]!=.&`varname'[_n-1]!=.&
>                         `varname'[_n]!=0&`varname'[_n-1]!=0&
>                         year[_n]==year[_n-1]+1,
>                         `varname'[_n]-`varname'[_n-1],.);
  3.         gen lag_`varname'=cond(
>                         id[_n]==id[_n-1]&
>                         state[_n]==state[_n-1]&
>                         `varname'[_n]!=.&`varname'[_n-1]!=.&
>                         `varname'[_n]!=0&`varname'[_n-1]!=0&
>                         year[_n]==year[_n-1]+1,
>                         `varname'[_n-1],.);
  4.                                         };
(44,521 missing values generated)
(44,521 missing values generated)

. sum Diri d_iri;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        Diri |    263,577   -1.215084    28.56901       -554        592
       d_iri |    263,577   -1.215084    28.56901       -554        592

.         drop d_iri;

. ** indicator for states with maintenance reported in HPMS;
. *bysort state year : egen D_exp_I2=max(I2_t) if I2_t!=.;
.  *label var D_exp_I2 "Dummy=1 for state year if if at least one sample id reports maintenance";
.         *keep if _n<50;
. *Total lane miles IH in each state-year;
.  bysort state year : egen lane_miles_st=total(lane_miles);

. label var  lane_miles_st "Total IH lane miles in state year (HPMS-sample)" ;

. *Total lane miles resurfaced IH in each state-year;
.  gen lane_miles_x=I2_t*lane_miles;
(673 missing values generated)

. bysort state year : egen lane_milesI2_st=total(lane_miles_x);

. drop lane_miles_x;

. label var  lane_milesI2_st "Total I2 IH lane miles in state year (HPMS-sample)" ;

. *keep year state lane_miles lane_miles_st lane_milesI2_st I2_t;
. *order year state lane_miles lane_miles_st lane_milesI2_st I2_t;
. * Real IH Expenditure per IH lane mile;
. gen app_IH_plm=                 (app_IH_r/lane_miles_st );
(77,531 missing values generated)

. gen exp_IRI_IH_SF12a_plm=       (exp_IRI_IH_SF12a_r/lane_miles_st );
(673 missing values generated)

. gen exp_L_IH_SF12a_plm=         (exp_L_IH_SF12a_r/lane_miles_st );
(673 missing values generated)

. label var app_IH_plm            "Appropriations per lane mile" ;

. label var exp_IRI_IH_SF12a_plm  "Exp. Resurfacing per lane mile" ;

. label var exp_L_IH_SF12a_plm    "Exp. construction per lane mile" ;

. * Real IH Expenditure per resurfaced IH lane mile;
. gen app_IH_I2_plm=                      (app_IH_r/lane_milesI2_st );
(126,970 missing values generated)

. gen exp_IRI_IH_I2_SF12a_plm=            (exp_IRI_IH_SF12a_r/lane_milesI2_st );
(59,249 missing values generated)

. gen exp_L_IH_I2_SF12a_plm=              (exp_L_IH_SF12a_r/lane_milesI2_st );
(59,249 missing values generated)

. label var app_IH_I2_plm                 "Appropriations per resurf.lane m." ;

. label var exp_IRI_IH_I2_SF12a_plm       "Exp. Resurfacing per resurf. lane m." ;

. label var exp_L_IH_I2_SF12a_plm         "Exp. Construction per resurf.lane m." ;

. forvalues i=1(1)5{;
  2.                                 gen L`i'FHWA_apport_LW_r_plm=                   (L`i'FHWA_apport_LW_r/
> lane_milesI2_st );
  3. };
(59,279 missing values generated)
(59,279 missing values generated)
(59,279 missing values generated)
(59,279 missing values generated)
(59,279 missing values generated)

.         tab state year if Diri==.;

                     |                             Book year
     State fips code |      1980       1981       1982       1983       1984       1985 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         1          1          1          1          1          1 |       439 
             ARIZONA |         1          1          1          1          1          1 |     1,064 
            ARKANSAS |         1          1          1          1          1          1 |       641 
          CALIFORNIA |         1          1          1          1          1          1 |     1,437 
            COLORADO |         1          1          1          1          1          1 |       492 
         CONNECTICUT |         1          1          1          1          1          1 |     1,397 
            DELAWARE |         1          1          1          1          1          1 |       111 
DISTRICT OF COLUMBIA |         0          0          0          0          0          0 |        78 
             FLORIDA |         1          1          1          1          1          1 |     1,548 
             GEORGIA |         1          1          1          1          1          1 |     1,267 
               IDAHO |         1          1          1          1          1          1 |       492 
            ILLINOIS |         1          1          1          1          1          1 |       846 
             INDIANA |         1          1          1          1          1          1 |       683 
                IOWA |         1          1          1          1          1          1 |     2,175 
              KANSAS |         1          1          1          1          1          1 |       769 
            KENTUCKY |         1          1          1          1          1          1 |       767 
           LOUISIANA |         1          1          1          1          1          1 |     1,301 
               MAINE |         1          1          1          1          1          1 |     1,256 
            MARYLAND |         1          1          1          1          1          1 |       674 
       MASSACHUSETTS |         1          1          1          1          1          1 |     1,370 
            MICHIGAN |         1          1          1          1          1          1 |     1,280 
           MINNESOTA |         1          1          1          1          1          1 |       289 
         MISSISSIPPI |         1          1          1          1          1          1 |       497 
            MISSOURI |         1          1          1          1          1          1 |       537 
             MONTANA |         1          1          1          1          1          1 |       308 
            NEBRASKA |         1          1          1          1          1          1 |       243 
              NEVADA |         1          1          1          1          1          1 |       701 
       NEW HAMPSHIRE |         1          1          1          1          1          1 |       489 
          NEW JERSEY |         1          1          1          1          1          1 |       704 
          NEW MEXICO |         1          1          1          1          1          1 |       537 
            NEW YORK |         1          1          1          1          1          1 |       760 
      NORTH CAROLINA |         1          1          1          1          1          1 |       840 
        NORTH DAKOTA |         1          1          1          1          1          1 |       252 
                OHIO |         1          1          1          1          1          1 |     1,407 
            OKLAHOMA |         1          1          1          1          1          1 |     1,762 
              OREGON |         1          1          1          1          1          1 |       940 
        PENNSYLVANIA |         1          1          1          1          1          1 |     4,911 
        RHODE ISLAND |         1          1          1          1          1          1 |       278 
      SOUTH CAROLINA |         1          1          1          1          1          1 |       431 
        SOUTH DAKOTA |         1          1          1          1          1          1 |       528 
           TENNESSEE |         1          1          1          1          1          1 |     1,274 
               TEXAS |         1          1          1          1          1          1 |     1,487 
                UTAH |         1          1          1          1          1          1 |     1,019 
             VERMONT |         1          1          1          1          1          1 |       188 
            VIRGINIA |         1          1          1          1          1          1 |     1,073 
          WASHINGTON |         1          1          1          1          1          1 |       426 
       WEST VIRGINIA |         1          1          1          1          1          1 |     1,234 
           WISCONSIN |         1          1          1          1          1          1 |       930 
             WYOMING |         1          1          1          1          1          1 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |        48         48         48         48         48         48 |    44,521 


                     |                             Book year
     State fips code |      1986       1987       1988       1989       1990       1991 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         1          1        145        145          1          2 |       439 
             ARIZONA |         1          1        174        177          0          1 |     1,064 
            ARKANSAS |         1          1        123        123         67         62 |       641 
          CALIFORNIA |         1          1        400        400          9         32 |     1,437 
            COLORADO |         1          1        246          7          6          1 |       492 
         CONNECTICUT |         1          1        226        230         19         18 |     1,397 
            DELAWARE |         1          1         23         25          1          0 |       111 
DISTRICT OF COLUMBIA |         0          0         15         15         15          0 |        78 
             FLORIDA |         1          1        276        279        280         22 |     1,548 
             GEORGIA |         1          1        283          8          1          3 |     1,267 
               IDAHO |         1          1        169        170          1          6 |       492 
            ILLINOIS |         1          1        306          0          3         61 |       846 
             INDIANA |         1          1        162        162        166          2 |       683 
                IOWA |         1          1        423        423        423        114 |     2,175 
              KANSAS |         1          1        186        189         58         55 |       769 
            KENTUCKY |         1          1        215        219          0          0 |       767 
           LOUISIANA |         1          1        184        203        203         44 |     1,301 
               MAINE |         1          1        168        168        168          2 |     1,256 
            MARYLAND |         1          1        196         45         49         65 |       674 
       MASSACHUSETTS |         1          1        427        427          5          1 |     1,370 
            MICHIGAN |         1          1        373        374         14         29 |     1,280 
           MINNESOTA |         1          1        148          1          0          4 |       289 
         MISSISSIPPI |         1          1        163        170          2          0 |       497 
            MISSOURI |         1          1        153        153          2          1 |       537 
             MONTANA |         1          1        196         16          0          0 |       308 
            NEBRASKA |         1          1         89         89          0          2 |       243 
              NEVADA |         1          1        151        152          0          0 |       701 
       NEW HAMPSHIRE |         1          1        118        118          0          0 |       489 
          NEW JERSEY |         1          1        169        181         40         34 |       704 
          NEW MEXICO |         1          1        262         27          4          0 |       537 
            NEW YORK |         1          1        315          2          0         20 |       760 
      NORTH CAROLINA |         1          1        158        159         46         21 |       840 
        NORTH DAKOTA |         1          1        110        110          1          1 |       252 
                OHIO |         1          1        401        397         77          0 |     1,407 
            OKLAHOMA |         1          1        247        425        216        220 |     1,762 
              OREGON |         1          1        202        202          0          1 |       940 
        PENNSYLVANIA |         1          1        749      1,532        287         84 |     4,911 
        RHODE ISLAND |         1          1         42         42         42          0 |       278 
      SOUTH CAROLINA |         1          1        141        141          2          0 |       431 
        SOUTH DAKOTA |         1          1        134        134          5          0 |       528 
           TENNESSEE |         1          1        252        252          0          0 |     1,274 
               TEXAS |         1          1        406          3          1          9 |     1,487 
                UTAH |         1          1        289        290          1          3 |     1,019 
             VERMONT |         1          1         90         56          0          0 |       188 
            VIRGINIA |         1          1        243        243          5          0 |     1,073 
          WASHINGTON |         1          1        199          2          1          0 |       426 
       WEST VIRGINIA |         1          1        383        400          0         20 |     1,234 
           WISCONSIN |         1          1        164        164        165          3 |       930 
             WYOMING |         1          1        121        123         49          9 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |        48         48     10,815      9,373      2,435        952 |    44,521 


                     |                             Book year
     State fips code |      1992       1993       1994       1995       1996       1997 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |        11         48          8          0          1          0 |       439 
             ARIZONA |         2         57          0          4        417          0 |     1,064 
            ARKANSAS |        26         29         42          5          2          5 |       641 
          CALIFORNIA |        21        239          7          4         12         19 |     1,437 
            COLORADO |        22         52          7         11          4          2 |       492 
         CONNECTICUT |        25        128          6        285        273         15 |     1,397 
            DELAWARE |         0         33          0          4          0          0 |       111 
DISTRICT OF COLUMBIA |         0         15          0          0          0          0 |        78 
             FLORIDA |         2        138         70         15         62         49 |     1,548 
             GEORGIA |        24        139        131         96         97         96 |     1,267 
               IDAHO |        10          0          0          0          0          2 |       492 
            ILLINOIS |        76        221         92         10          3          1 |       846 
             INDIANA |         9          2         60          5          2          4 |       683 
                IOWA |        39        392         23         55         46         22 |     2,175 
              KANSAS |        76        100          3          2          3          3 |       769 
            KENTUCKY |        10         84          5          1          1          0 |       767 
           LOUISIANA |        65        104         46         43         34         18 |     1,301 
               MAINE |         1         12         64          6          6          7 |     1,256 
            MARYLAND |        51        144          4         10          7          2 |       674 
       MASSACHUSETTS |         0        300         16          0          4         10 |     1,370 
            MICHIGAN |        48        156         86         80          1          0 |     1,280 
           MINNESOTA |         2         53          0          0          1          1 |       289 
         MISSISSIPPI |         5         35          0         10          5          4 |       497 
            MISSOURI |         9         62          3          0          0          0 |       537 
             MONTANA |         6         29          6          6          6          0 |       308 
            NEBRASKA |         4         22          8          0          0          0 |       243 
              NEVADA |        11        158        156         18         13          1 |       701 
       NEW HAMPSHIRE |         3          3          0          0          0          0 |       489 
          NEW JERSEY |         9          8        135          6          4          6 |       704 
          NEW MEXICO |         8          1         47          2          0          1 |       537 
            NEW YORK |        13        235          4          6          4          4 |       760 
      NORTH CAROLINA |        51        103         10         21          7          4 |       840 
        NORTH DAKOTA |         1          1          0          0          0          9 |       252 
                OHIO |         7        242         39          2          4          0 |     1,407 
            OKLAHOMA |         9        441          0         20          0          0 |     1,762 
              OREGON |         2         54          1          0          0          0 |       940 
        PENNSYLVANIA |       163        666          0         28        119         65 |     4,911 
        RHODE ISLAND |         3         36          0          0          0         46 |       278 
      SOUTH CAROLINA |         2         55         21          4          0          0 |       431 
        SOUTH DAKOTA |         0        117          3          5          2         16 |       528 
           TENNESSEE |       253        253          3          5         21         25 |     1,274 
               TEXAS |         2         27        129        151        135         15 |     1,487 
                UTAH |        28         94          2          1          3          0 |     1,019 
             VERMONT |         2          0          0          0          0          0 |       188 
            VIRGINIA |         1        135         25          0          0          0 |     1,073 
          WASHINGTON |        47         52          0          0          0          0 |       426 
       WEST VIRGINIA |         0         13          0          5          0          0 |     1,234 
           WISCONSIN |        11         45          5          3         19          0 |       930 
             WYOMING |        18          2         27          0          0          0 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |     1,188      5,335      1,294        929      1,318        452 |    44,521 


                     |                             Book year
     State fips code |      1998       1999       2000       2001       2002       2003 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         0         22          3          0          2          0 |       439 
             ARIZONA |         0          0          0         29          1         66 |     1,064 
            ARKANSAS |         5         14         69          2          1          0 |       641 
          CALIFORNIA |        89          9         17          0          9          8 |     1,437 
            COLORADO |         3         13         10          3          1         27 |       492 
         CONNECTICUT |         2         45         18          2         76          7 |     1,397 
            DELAWARE |         0          0          0          0          1          1 |       111 
DISTRICT OF COLUMBIA |         0         15          1          1          1          0 |        78 
             FLORIDA |        32         70         33         28         51         11 |     1,548 
             GEORGIA |        73         53         25          6          0         11 |     1,267 
               IDAHO |         1         61         21          0          0         14 |       492 
            ILLINOIS |         0         23          0          2          5          1 |       846 
             INDIANA |         2         55          0          0          2          0 |       683 
                IOWA |        20         59         19          3         16         29 |     2,175 
              KANSAS |         7         21         20          5          5          2 |       769 
            KENTUCKY |         0         16          7        127          1         31 |       767 
           LOUISIANA |         6        118          3          2         23         20 |     1,301 
               MAINE |        33        115         52          0          4         10 |     1,256 
            MARYLAND |         3         14          3          3         13         35 |       674 
       MASSACHUSETTS |        16          7          5          0         31         57 |     1,370 
            MICHIGAN |         0         14          1         11          0         43 |     1,280 
           MINNESOTA |         0         19          0          0          1          3 |       289 
         MISSISSIPPI |         4         14          0          4          5         27 |       497 
            MISSOURI |         1          8          0          6          0          5 |       537 
             MONTANA |         0          8          0          0          0         16 |       308 
            NEBRASKA |         0          1          9          0          0          2 |       243 
              NEVADA |         0          2          0          0          0          0 |       701 
       NEW HAMPSHIRE |         0         24         79         32          0         51 |       489 
          NEW JERSEY |         5          9         12          3          1         46 |       704 
          NEW MEXICO |         1         90          7          0         14         12 |       537 
            NEW YORK |         0         30          0          0          8          0 |       760 
      NORTH CAROLINA |        11         51         14          3         30         30 |       840 
        NORTH DAKOTA |         0          0          0          0          0          2 |       252 
                OHIO |         1         86          1          4          1         60 |     1,407 
            OKLAHOMA |         0         59          3          9         10         60 |     1,762 
              OREGON |         0        308         27         27          0          3 |       940 
        PENNSYLVANIA |         3         31         21         88        471        264 |     4,911 
        RHODE ISLAND |        46          1          3          3          0          0 |       278 
      SOUTH CAROLINA |         0          7          0          0          0          8 |       431 
        SOUTH DAKOTA |        24         35          5          1          4          4 |       528 
           TENNESSEE |        26         25         10          3         30         69 |     1,274 
               TEXAS |         3        162          6          5         60        160 |     1,487 
                UTAH |         3        133         65         11         11         16 |     1,019 
             VERMONT |         0          8          0          0          1          0 |       188 
            VIRGINIA |         1        325          4          6         17         10 |     1,073 
          WASHINGTON |         0         33          0          0          0          5 |       426 
       WEST VIRGINIA |         1         15         85          0          7          0 |     1,234 
           WISCONSIN |         6         14        208          0          1         57 |       930 
             WYOMING |        23          0          0          0          0          0 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |       451      2,242        866        429        915      1,283 |    44,521 


                     |                             Book year
     State fips code |      2004       2005       2006       2007       2008       2009 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         6         10          1          9         11          1 |       439 
             ARIZONA |        71          1          1          0         49          1 |     1,064 
            ARKANSAS |        10         23         16          3          0          1 |       641 
          CALIFORNIA |        18         43         69          7         11          1 |     1,437 
            COLORADO |         3         34         21          0          5          1 |       492 
         CONNECTICUT |         3          1          3          1          0          1 |     1,397 
            DELAWARE |         0          2          7          0          0          1 |       111 
DISTRICT OF COLUMBIA |         0          0          0          0          0          0 |        78 
             FLORIDA |        49         40          6          6         15          1 |     1,548 
             GEORGIA |        69          9         14         60         55          1 |     1,267 
               IDAHO |         2         19          1          1          0          1 |       492 
            ILLINOIS |        12          6          9          1          0          1 |       846 
             INDIANA |         1          0          0         33          2          1 |       683 
                IOWA |        13         11          6          8         17          1 |     2,175 
              KANSAS |        14          5          0          1          0          1 |       769 
            KENTUCKY |        12          0          3          7         14          1 |       767 
           LOUISIANA |        42         44         20         32         33          1 |     1,301 
               MAINE |       302         42         74          8          0          1 |     1,256 
            MARYLAND |        15          1          0          0          0          1 |       674 
       MASSACHUSETTS |        15         12          7          8          8          1 |     1,370 
            MICHIGAN |        10         13         11          2          0          1 |     1,280 
           MINNESOTA |        28          0          0          8          6          1 |       289 
         MISSISSIPPI |         6          5         15          3          6          1 |       497 
            MISSOURI |        63          4          1         50          2          1 |       537 
             MONTANA |         2          2          1          0          0          1 |       308 
            NEBRASKA |         2          0          1          0          0          1 |       243 
              NEVADA |        21          2          0          0          2          1 |       701 
       NEW HAMPSHIRE |        27          1          2          3         14          1 |       489 
          NEW JERSEY |         2          5          5          3          7          1 |       704 
          NEW MEXICO |        15          0          0          0         32          1 |       537 
            NEW YORK |         0          0         82          9         14          1 |       760 
      NORTH CAROLINA |         4         95          0          4          4          1 |       840 
        NORTH DAKOTA |         2          0          1          0          0          1 |       252 
                OHIO |        45         24          2          0          0          1 |     1,407 
            OKLAHOMA |         0         13         13          3          0          1 |     1,762 
              OREGON |        82          4          6          4          3          1 |       940 
        PENNSYLVANIA |       135         25         12         65         89          1 |     4,911 
        RHODE ISLAND |         0          0          0          0          0          1 |       278 
      SOUTH CAROLINA |         3         23          0          8          2          1 |       431 
        SOUTH DAKOTA |        15          0          0         10          0          1 |       528 
           TENNESSEE |        32          0          0          1          0          1 |     1,274 
               TEXAS |        21         39         43         12         84          1 |     1,487 
                UTAH |        27          1          7          2         18          1 |     1,019 
             VERMONT |         0         17          0          0          0          1 |       188 
            VIRGINIA |        25         15          0          2          2          1 |     1,073 
          WASHINGTON |        31          0          0         24         18          1 |       426 
       WEST VIRGINIA |         0         56        182         18         35          1 |     1,234 
           WISCONSIN |        44          2          2          0          3          1 |       930 
             WYOMING |         0          0          2          1          0          1 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |     1,299        649        646        417        561         48 |    44,521 


                     |                       Book year
     State fips code |      2010       2011       2012       2013       2014 |     Total
---------------------+-------------------------------------------------------+----------
             ALABAMA |         1          1          1          1          1 |       439 
             ARIZONA |         1          1          1          1          1 |     1,064 
            ARKANSAS |         1          1          1          1          1 |       641 
          CALIFORNIA |         1          1          1          1          1 |     1,437 
            COLORADO |         1          1          1          1          1 |       492 
         CONNECTICUT |         1          1          1          1          1 |     1,397 
            DELAWARE |         1          1          1          1          1 |       111 
DISTRICT OF COLUMBIA |         0          0          0          0          0 |        78 
             FLORIDA |         1          1          1          1          1 |     1,548 
             GEORGIA |         1          1          1          1          1 |     1,267 
               IDAHO |         1          1          1          1          1 |       492 
            ILLINOIS |         1          1          1          1          1 |       846 
             INDIANA |         1          1          1          1          1 |       683 
                IOWA |         1          1          1          1          1 |     2,175 
              KANSAS |         1          1          1          1          1 |       769 
            KENTUCKY |         1          1          1          1          1 |       767 
           LOUISIANA |         1          1          1          1          1 |     1,301 
               MAINE |         1          1          1          1          1 |     1,256 
            MARYLAND |         1          1          1          1          1 |       674 
       MASSACHUSETTS |         1          1          1          1          1 |     1,370 
            MICHIGAN |         1          1          1          1          1 |     1,280 
           MINNESOTA |         1          1          1          1          1 |       289 
         MISSISSIPPI |         1          1          1          1          1 |       497 
            MISSOURI |         1          1          1          1          1 |       537 
             MONTANA |         1          1          1          1          1 |       308 
            NEBRASKA |         1          1          1          1          1 |       243 
              NEVADA |         1          1          1          1          1 |       701 
       NEW HAMPSHIRE |         1          1          1          1          1 |       489 
          NEW JERSEY |         1          1          1          1          1 |       704 
          NEW MEXICO |         1          1          1          1          1 |       537 
            NEW YORK |         1          1          1          1          1 |       760 
      NORTH CAROLINA |         1          1          1          1          1 |       840 
        NORTH DAKOTA |         1          1          1          1          1 |       252 
                OHIO |         1          1          1          1          1 |     1,407 
            OKLAHOMA |         1          1          1          1          1 |     1,762 
              OREGON |         1          1          1          1          1 |       940 
        PENNSYLVANIA |         1          1          1          1          1 |     4,911 
        RHODE ISLAND |         1          1          1          1          1 |       278 
      SOUTH CAROLINA |         1          1          1          1          1 |       431 
        SOUTH DAKOTA |         1          1          1          1          1 |       528 
           TENNESSEE |         1          1          1          1          1 |     1,274 
               TEXAS |         1          1          1          1          1 |     1,487 
                UTAH |         1          1          1          1          1 |     1,019 
             VERMONT |         1          1          1          1          1 |       188 
            VIRGINIA |         1          1          1          1          1 |     1,073 
          WASHINGTON |         1          1          1          1          1 |       426 
       WEST VIRGINIA |         1          1          1          1          1 |     1,234 
           WISCONSIN |         1          1          1          1          1 |       930 
             WYOMING |         1          1          1          1          1 |       389 
---------------------+-------------------------------------------------------+----------
               Total |        48         48         48         48         48 |    44,521 

. *drop state-years with no resurfacing expenditure;
. drop if exp_IRI_IH_SF12a_r==0;
(5,758 observations deleted)

. drop if exp_IRI_IH_SF12a_r==.;
(0 observations deleted)

. *drop id-years with bad IRI data;
. drop if Diri==.;
(41,806 observations deleted)

. drop if abs(Diri)>200;
(344 observations deleted)

. *drop state-years with no resurfacing;
. drop if lane_milesI2_st==.|lane_milesI2_st==0;
(50,587 observations deleted)

. *drop DC and years outside sample;
. drop if state==11;
(0 observations deleted)

. drop if year<1992;
(23,548 observations deleted)

. drop if year>2008;
(0 observations deleted)

. tab state;

     State fips code |      Freq.     Percent        Cum.
---------------------+-----------------------------------
             ALABAMA |      1,169        0.63        0.63
             ARIZONA |      8,057        4.33        4.96
            ARKANSAS |      1,877        1.01        5.97
          CALIFORNIA |      6,247        3.36        9.33
            COLORADO |      2,132        1.15       10.47
         CONNECTICUT |      3,652        1.96       12.43
            DELAWARE |        171        0.09       12.53
             FLORIDA |      4,462        2.40       14.92
             GEORGIA |      3,607        1.94       16.86
               IDAHO |      2,799        1.50       18.37
            ILLINOIS |      3,718        2.00       20.37
                IOWA |      3,932        2.11       22.48
              KANSAS |      1,762        0.95       23.43
            KENTUCKY |      2,749        1.48       24.90
           LOUISIANA |      2,098        1.13       26.03
               MAINE |      2,057        1.11       27.14
            MARYLAND |      4,420        2.38       29.51
       MASSACHUSETTS |      2,135        1.15       30.66
            MICHIGAN |      4,737        2.55       33.21
           MINNESOTA |      2,251        1.21       34.42
         MISSISSIPPI |      1,197        0.64       35.06
            MISSOURI |      1,555        0.84       35.89
             MONTANA |      2,911        1.56       37.46
            NEBRASKA |      1,643        0.88       38.34
              NEVADA |      1,363        0.73       39.08
       NEW HAMPSHIRE |      1,884        1.01       40.09
          NEW JERSEY |      2,593        1.39       41.48
          NEW MEXICO |      2,201        1.18       42.66
            NEW YORK |      5,272        2.83       45.50
      NORTH CAROLINA |      4,507        2.42       47.92
        NORTH DAKOTA |      1,623        0.87       48.79
                OHIO |      7,468        4.01       52.81
            OKLAHOMA |      2,488        1.34       54.14
              OREGON |      5,303        2.85       56.99
        PENNSYLVANIA |     47,182       25.36       82.35
        RHODE ISLAND |        325        0.17       82.53
      SOUTH CAROLINA |      1,111        0.60       83.12
        SOUTH DAKOTA |      2,865        1.54       84.66
           TENNESSEE |      2,181        1.17       85.84
               TEXAS |      7,085        3.81       89.64
                UTAH |      2,588        1.39       91.04
             VERMONT |      1,326        0.71       91.75
            VIRGINIA |      2,191        1.18       92.93
          WASHINGTON |      2,366        1.27       94.20
       WEST VIRGINIA |      6,434        3.46       97.66
           WISCONSIN |      2,491        1.34       98.99
             WYOMING |      1,870        1.01      100.00
---------------------+-----------------------------------
               Total |    186,055      100.00

. *aadt variables;
.         gen aadt2_10000=aadt_1000^2;

. label var aadt2_10000 "(`:  var label aadt_1000')^2" ;

. gen aadt3_10000=aadt_1000^3;

. label var aadt3_10000 "(`:  var label aadt_1000')^3" ;

.         *Set up state year and I2 x year FE;
. *calculate number of years that each state is present in data;
. preserve;

.         sort state year;

.         by state year: gen counter1=_n;

.         keep if counter1==1;
(185,480 observations deleted)

.         display "count number of stateXyears for reference";
count number of stateXyears for reference

.         sum year;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        year |        575     1999.61    4.837559       1992       2008

.         sort state;

.         by state: gen num_years=_N;

.         by state: gen counter3=_n;

.         keep if counter3==1;
(528 observations deleted)

.         label var num_years "Years state present in data";

.         keep state num_years;

.         tab num_years;

Years state |
 present in |
       data |      Freq.     Percent        Cum.
------------+-----------------------------------
          5 |          2        4.26        4.26
          6 |          1        2.13        6.38
          7 |          2        4.26       10.64
          8 |          3        6.38       17.02
          9 |          5       10.64       27.66
         10 |          6       12.77       40.43
         12 |          2        4.26       44.68
         13 |          2        4.26       48.94
         14 |         10       21.28       70.21
         15 |          5       10.64       80.85
         16 |          2        4.26       85.11
         17 |          7       14.89      100.00
------------+-----------------------------------
      Total |         47      100.00

.         display "states present 1990-2008 --- use Texas 1990 for omitted state-year";
states present 1990-2008 --- use Texas 1990 for omitted state-year

.         tab state if num_years==18;
no observations

.         tab state if num_years==18, nol;
no observations

. // Texas, fips 48 is present in all years
>         sort state;

.         save stateyears,replace;
(file stateyears.dta not found)
file stateyears.dta saved

. restore;

. merge m:1 state using stateyears;
(label fips already defined)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                           186,055  (_merge==3)
    -----------------------------------------

. tab _merge;

   Matching result from |
                  merge |      Freq.     Percent        Cum.
------------------------+-----------------------------------
            Matched (3) |    186,055      100.00      100.00
------------------------+-----------------------------------
                  Total |    186,055      100.00

. order state state_name year num_years;

. erase stateyears.dta;

. *make state-year indicators for state years present in data;
.         levelsof year, local(year_list);
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. levelsof state, local(state_list);
1 4 5 6 8 9 10 12 13 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46
>  47 48 49 50 51 53 54 55 56

. display "`state_list'";
1 4 5 6 8 9 10 12 13 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46
>  47 48 49 50 51 53 54 55 56

. display "`year_list'";
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. local i_stateyear=1;

. foreach k_year of local year_list{;
  2.         foreach k_state of local state_list{;
  3.                 if !("`k_year'"=="1990"&"`k_state'"=="48"){;
  4.  //texas 1990 omitted
>                         *make dummy for state-year;
.                         gen stateXyearI_`k_year'_`k_state'=cond(year==`k_year'&state==`k_state',1,0);
  5.                         *drop indicator if state-year missing from data;
.                         quiet sum stateXyearI_`k_year'_`k_state';
  6.                         local tester =r(mean) ;
  7.                         if `tester'==0{;
  8.                                 drop stateXyearI_`k_year'_`k_state';
  9.                                 };
 10.                         *increment counter if state-year present in data. counter is just used as a di
> agnostic;
.                         if `tester'>0{;
 11.                                 local ++i_stateyear;
 12.                                 };
 13.                         };
 14. //end skip texas 1990 if
>                 };
 15. //end state loop
>         };

. //end year loop
> display "`i_stateyear'-1 state-year indicators created -- should match tab above";
576-1 state-year indicators created -- should match tab above

. *make year X I2_t indicators and year X I2_t * expenditure per mile variables;
.         levelsof year, local(year_list);
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. display "`year_list'";
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. foreach k_year of local year_list{;
  2.         gen I2_t_x`k_year'                      =cond(year==`k_year'& I2_t==1,1,0);
  3.         gen I2_t_`k_year'_exp_I2        =I2_t_x`k_year'*exp_IRI_IH_SF12a_plm;
  4.         gen I2_t_`k_year'_exp_L         =I2_t_x`k_year'*exp_L_IH_I2_SF12a_plm;
  5.                         label var I2_t_`k_year'_exp_I2          "IRI exp per I2 lane mile `k_year'";
  6.         label var I2_t_`k_year'_exp_L           "L exp per I2 lane mile `k_year'";
  7.         };

. //end year loop
> 
>         
>         
> gen urban=1 if  D_urban==1 | D_small_urban==1;
(91,747 missing values generated)

. replace urban =0 if D_rural==1 ;
(91,747 real changes made)

. label var urban "Dummy=1 if urban" ;

.                                         * time, for estimating trends;
. gen time =year-1990;

. gen time2 =time^2;

. gen time3 =time^3;

. label var time2 "\(time^2\)" ;

. label var time3 "\(time^3\)" ;

. *TIME TREND DUMMIES;
. gen     periods=1 if  year>=1984&year<=1989;
(186,055 missing values generated)

. replace periods=2 if  year>=1990&year<=1994;
(28,365 real changes made)

. replace periods=3 if  year>=1995&year<=1999;
(55,231 real changes made)

. replace periods=4 if  year>=2000&year<=2004;
(58,770 real changes made)

. replace periods=5 if  year>=2005&year<=2008;
(43,689 real changes made)

. tab year periods, m ;

           |                   periods
 Book year |         2          3          4          5 |     Total
-----------+--------------------------------------------+----------
      1992 |    10,524          0          0          0 |    10,524 
      1993 |     6,932          0          0          0 |     6,932 
      1994 |    10,909          0          0          0 |    10,909 
      1995 |         0     10,735          0          0 |    10,735 
      1996 |         0     11,646          0          0 |    11,646 
      1997 |         0     11,080          0          0 |    11,080 
      1998 |         0     11,326          0          0 |    11,326 
      1999 |         0     10,444          0          0 |    10,444 
      2000 |         0          0     11,846          0 |    11,846 
      2001 |         0          0     12,857          0 |    12,857 
      2002 |         0          0     10,956          0 |    10,956 
      2003 |         0          0     11,547          0 |    11,547 
      2004 |         0          0     11,564          0 |    11,564 
      2005 |         0          0          0     10,878 |    10,878 
      2006 |         0          0          0     10,944 |    10,944 
      2007 |         0          0          0     10,840 |    10,840 
      2008 |         0          0          0     11,027 |    11,027 
-----------+--------------------------------------------+----------
     Total |    28,365     55,231     58,770     43,689 |   186,055 

. label define periods 1 "1984-1989"
>                                         2 "1990-1994"
>                                         3 "1995-1999"
>                                         4 "2000-2004"
>                                         5 "2005-2008";

. label values periods periods;

. *** Gen state_year to cluster standar errors ;
. egen state_year= group(state year);

. *make I2_t * expenditure per mile variables;
.         foreach I in Ids_t Iall_t I2_t{;
  2.         gen `I'_exp_I2          =`I'*exp_IRI_IH_SF12a_plm;
  3.         gen `I'_exp_L           =`I'*exp_L_IH_I2_SF12a_plm;
  4.         gen `I'_app_I2                  =`I'*app_IH_I2_plm ;
  5.                 forvalues i=1(1)5{;
  6.                 gen `I'_L`i'_apport_I2=`I'*L`i'FHWA_apport_LW_r_plm;
  7.         };
  8.                         *LABEL FOR TEX OUPTU;
.         label var `I'_exp_I2            "\( \mathds{1}_{ist}(q)\imath^q_{st}\)";
  9. };
(17,456 missing values generated)
(17,456 missing values generated)
(17,456 missing values generated)

.         # d cr ;
delimiter now cr
.         
. 
end of do-file

. order irsstatecode state state_name id year I2_t ${var_outcomes} ${more_var};

. keep  irsstatecode state state_name id year I2_t  ${var_outcomes} ${more_var};

. sort id year ;

. drop if year<1992;
(0 observations deleted)

. *----------------------------------------------------------------------------------;
. * - Keep only the segments with resurfacing events ;
.  *----------------------------------------------------------------------------------;
. bys id: egen maintained=total(I2_t);

. tab maintained, m;

 maintained |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |    110,917       59.62       59.62
          1 |     60,941       32.75       92.37
          2 |     12,615        6.78       99.15
          3 |      1,504        0.81       99.96
          4 |         65        0.03       99.99
          5 |         13        0.01      100.00
------------+-----------------------------------
      Total |    186,055      100.00

.  drop if maintained==0;
(110,917 observations deleted)

. *----------------------------------------------------------------------------------;
. * - create and event indicator ;
. *----------------------------------------------------------------------------------;
. bys id: gen xx=cond(I2_t==1,1,.);
(67,126 missing values generated)

. bys id: gen segment_event=sum(xx);

. *mt -- it would be better to do this yourself.  Then the information on segment id and event would be enc
> oded in the ID if we ever want it;
. tostring segment_event, gen(yyy);
yyy generated as str1

. gen id_event= id+ ":" +yyy  ;

. drop yyy;

. *** This a tricky step. I define a time for each event within a segment so I can recover
>         the full information for that segment;
. forvalues i=1(1)5{;
  2.         gen ww`i'= year*xx if segment_event==`i';
  3.         gen yy`i'= year if segment_event==`i';
  4.         bys id: egen event_year`i'=mean(ww`i');
  5.         bys id: egen max_year`i'=max(yy`i');
  6.         bys id: egen min_year`i'=min(yy`i');
  7.                                 gen time`i'=year-event_year`i' ;
  8.         drop ww`i' yy`i';
  9.         };
(68,301 missing values generated)
(33,118 missing values generated)
(74,086 missing values generated)
(70,621 missing values generated)
(60,941 missing values generated)
(60,941 missing values generated)
(60,941 missing values generated)
(60,941 missing values generated)
(75,021 missing values generated)
(74,735 missing values generated)
(73,556 missing values generated)
(73,556 missing values generated)
(73,556 missing values generated)
(73,556 missing values generated)
(75,133 missing values generated)
(75,122 missing values generated)
(75,060 missing values generated)
(75,060 missing values generated)
(75,060 missing values generated)
(75,060 missing values generated)
(75,137 missing values generated)
(75,137 missing values generated)
(75,125 missing values generated)
(75,125 missing values generated)
(75,125 missing values generated)
(75,125 missing values generated)

. sort id year ;

. *----------------------------------------------------------------------------------;
. *- Create a dataset at the event level with all the information of the ;
. *----------------------------------------------------------------------------------;
. bys id: egen last_year=max(year);

. preserve ;

.         keep irsstatecode id  year I2_t ${more_var} ;

.         save "temp_var", replace ;
(file temp_var.dta not found)
file temp_var.dta saved

. restore;

.  keep irsstatecode id year   last_year I2_t ${var_outcomes} time* event_year* max_year* min_year*;

. * In this step I create the data at the segment -event level. For each event
>  I keep all the infomation of segment. -- (tricky);
.  reshape long time event_year max_year min_year , i( irsstatecode id  year I2_t ${var_outcomes}  last_yea
> r ) j(segment_event );
(j = 1 2 3 4 5)

Data                               Wide   ->   Long
-----------------------------------------------------------------------------
Number of observations           75,138   ->   375,690     
Number of variables                  30   ->   15          
j variable (5 values)                     ->   segment_event
xij variables:
                  time1 time2 ... time5   ->   time
event_year1 event_year2 ... event_year5   ->   event_year
      max_year1 max_year2 ... max_year5   ->   max_year
      min_year1 min_year2 ... min_year5   ->   min_year
-----------------------------------------------------------------------------

. sort  id segment_event time;

. order  id segment_event time;

. *generate id;
. tostring segment_event, gen(yyy);
yyy generated as str1

. gen id_event= id+ ":" +yyy  ;

. drop  yyy;

. sort id segment_event year ;

. order id segment_event  id_event year;

. drop if time==.;
(284,682 observations deleted)

. *add the additional variables I want to have;
.  merge m:1 id year using  "temp_var", nogen ;
(label surface_cat already defined)
(label Dcat_surface_cat already defined)
(label surface_type already defined)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                            91,008  
    -----------------------------------------

. erase "temp_var.dta";

. *----------------------------------------------------------------------------------;
. * - save data in long format  ;
. *----------------------------------------------------------------------------------;
. sort id segment_event year ;

. gen lenght=max_year - event_year;

. gen         D_surface=Dcat_surface_cat;
(104 missing values generated)

.  replace D_surface=cond(Dcat_surface_cat==44 | Dcat_surface_cat==55 | Dcat_surface_cat==66 | Dcat_surface
> _cat==65 |  Dcat_surface_cat==0,Dcat_surface_cat,0);
(2,018 real changes made)

.   label define D_surface 0 "Other"
>                                            44 "Flexible"
>                                            55 "Rigid"
>                                            65 "Rig/Comp"
>                                            66 "Composite"
>                                            ;

. label values D_surface  D_surface ;

. gen censored=cond(max_year==last_year,1,0);

. label define censored 1 "Ends with last year of sample" 
>                                           0 "New resurfacing before last sample year" ;

.         label values censored censored ;

.                                           bys id_event (time): gen cumul_aadt=sum(aadt) if time>=0 ;
(38,676 missing values generated)

. **!! DO NOT CHANGE IT TO EGEN;
.                                   gen period=1 if event_year <1992;
(91,008 missing values generated)

. replace period=2 if event_year >=1992 & event_year <1996;
(21,835 real changes made)

. replace period=3 if event_year >=1996 & event_year <2000;
(25,995 real changes made)

. replace period=4 if event_year >=2000 & event_year <2005;
(25,541 real changes made)

. replace period=5 if event_year >=2005 & event_year  !=.  ;
(17,637 real changes made)

. label define period 1 "<92" 
>                                         2 "92-95"
>                                         3 "96-99"
>                                         4 "00-04"
>                                         5 "05-08";

. label values period period;

.                                         tab  year period;

           |                   period
 Book year |     92-95      96-99      00-04      05-08 |     Total
-----------+--------------------------------------------+----------
      1992 |     1,457      1,141        835        621 |     4,054 
      1993 |     1,328      1,103        921        618 |     3,970 
      1994 |     1,642      1,780      1,273        722 |     5,417 
      1995 |     1,550      1,791      1,324        874 |     5,539 
      1996 |     1,547      1,937      1,430        815 |     5,729 
      1997 |     1,518      1,925      1,504        870 |     5,817 
      1998 |     1,467      1,936      1,549        961 |     5,913 
      1999 |     1,369      1,905      1,472        822 |     5,568 
      2000 |     1,328      1,761      1,919      1,009 |     6,017 
      2001 |     1,332      1,745      2,058      1,162 |     6,297 
      2002 |     1,170      1,529      1,921      1,135 |     5,755 
      2003 |     1,188      1,447      1,934      1,232 |     5,801 
      2004 |     1,123      1,305      1,794      1,226 |     5,448 
      2005 |       955      1,249      1,509      1,259 |     4,972 
      2006 |       908      1,151      1,383      1,429 |     4,871 
      2007 |       952      1,163      1,331      1,450 |     4,896 
      2008 |     1,001      1,127      1,384      1,432 |     4,944 
-----------+--------------------------------------------+----------
     Total |    21,835     25,995     25,541     17,637 |    91,008 

. * Dummy for segments with multiple events;
.  bys id: egen xx=max(segment_event);

. gen multiple_events=cond(xx!=1,1,0);

.  tab multiple_events, m ;

multiple_ev |
       ents |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |     60,941       66.96       66.96
          1 |     30,067       33.04      100.00
------------+-----------------------------------
      Total |     91,008      100.00

.  drop xx ;

.  forvalues i=2(1)5{;
  2.         by id : gen xx`i'=event_year if segment_event==`i';
  3.         by id : egen year_event`i'=mean(xx`i');
  4.         drop xx`i';
  5. };
(76,811 missing values generated)
(60,941 missing values generated)
(89,426 missing values generated)
(86,171 missing values generated)
(90,930 missing values generated)
(90,683 missing values generated)
(90,995 missing values generated)
(90,943 missing values generated)

. gen next_event_year=.;
(91,008 missing values generated)

. gen next_event_gap=.;
(91,008 missing values generated)

. forvalues i=1(1)4{;
  2.         local j=`i'+1;
  3.         replace next_event_year=year_event`j' if segment_event==`i';
  4.         replace next_event_gap=next_event_year-event_year;
  5.                 drop  year_event`j';
  6.  };
(14,197 real changes made)
(14,197 real changes made)
(1,582 real changes made)
(1,582 real changes made)
(78 real changes made)
(78 real changes made)
(13 real changes made)
(13 real changes made)

. sort id id_event time;

. encode id_event, gen(id_event_code);

. xtset id_event_code time ;

Panel variable: id_event_code (unbalanced)
 Time variable: time, -16 to 16, but with gaps
         Delta: 1 unit

. replace sn=. if sn_d==0;
(21 real changes made, 21 to missing)

. tab period, m ;

     period |      Freq.     Percent        Cum.
------------+-----------------------------------
      92-95 |     21,835       23.99       23.99
      96-99 |     25,995       28.56       52.56
      00-04 |     25,541       28.06       80.62
      05-08 |     17,637       19.38      100.00
------------+-----------------------------------
      Total |     91,008      100.00

.  tab D_surface, gen(Surf_);

  D_surface |      Freq.     Percent        Cum.
------------+-----------------------------------
      Other |      2,417        2.66        2.66
   Flexible |     30,403       33.41       36.06
      Rigid |     21,619       23.76       59.82
   Rig/Comp |      1,500        1.65       61.47
  Composite |     35,069       38.53      100.00
------------+-----------------------------------
      Total |     91,008      100.00

. gen D_aadt_10000=aadt_10000-l.aadt_10000;
(13,810 missing values generated)

. label var  D_aadt_10000  "AADT(0)-AADT(-1)";

. gen D_sn_d=sn_d-l.sn_d;
(13,825 missing values generated)

. replace D_sn_d=.  if abs(D_sn_d)>5 & time==0;
(226 real changes made, 226 to missing)

. label var  D_sn_d  "SN(0)-SN(-1)";

. gen D_sn_d_2=sn_d-l2.sn_d;
(21,377 missing values generated)

. replace D_sn_d_2=.  if abs(D_sn_d_2)>5 & time==0;
(237 real changes made, 237 to missing)

. label var  D_sn_d_2 "SN(0)-SN(-2)";

. gen D_sn_d_1=f.sn_d-l.sn_d;
(25,093 missing values generated)

. replace D_sn_d_1=.  if abs(D_sn_d_2)>5 & time==0;
(1,180 real changes made, 1,180 to missing)

. label var  D_sn_d_1 "SN(1)-SN(-1)";

. gen D_iri=iri-l.iri;
(13,810 missing values generated)

. label var  D_iri "IRI(0)-IRI(-1)" ;

. gen Df4_iri=f4.iri-iri;
(33,168 missing values generated)

. replace Df4_iri=. if abs(Df4_iri)>30 & time==0;
(1,148 real changes made, 1,148 to missing)

. label var Df4_iri " IRI(4)-IRI(0)";

. gen Df3_iri=f3.iri-iri;
(27,799 missing values generated)

. replace Df3_iri=. if abs(Df3_iri)>30 & time==0;
(1,055 real changes made, 1,055 to missing)

. label var Df3_iri " IRI(3)-IRI(0)";

. *gen aadt_4yr=f4.aadt_10000+f3.aadt_1000+f2.aadt_10000+f1.aadt_10000 +aadt_10000;
. *label var aadt_4yr  "AADT(0)+AADT(1)+...+AADT(4)";
. gen aadt_3yr=f3.aadt_1000+f2.aadt_10000+f1.aadt_10000 +aadt_10000;
(34,850 missing values generated)

. label var aadt_3yr  "AADT(0)+AADT(1)+...+AADT(3)";

. *gen Df4_iri_by_aadt_4yr=Df4_iri/aadt_4yr;
. *label var Df4_iri_by_aadt_4yr " IRI/AADT using 4 year totals ";
.  gen Df3_iri_by_aadt_3yr=Df3_iri/aadt_3yr;
(35,748 missing values generated)

. label var Df3_iri_by_aadt_3yr " IRI/AADT using 3 year totals ";

.  gen Surf_all=1 ;

. ** Identify the events with huge changes in IRI and inspect them;
.  gen out_Diri3yr=cond(Df3_iri<-10 & time==0,1,0);

. bys id_event: egen segment_out_Diri3yr=max(out_Diri3yr);

. gen out_D_sn_d=cond(abs(D_sn_d)>4 & time==0 &D_sn_d!=.,1,0);

. bys id_event (time): egen segment_out_D_sn_d=max(out_D_sn_d);

. foreach x in next_event_gap D_surface irsstatecode urban event_year multiple_events next_event_gap {;
  2.  tab `x'  out_D_sn_d if time==0, m  row;
  3. };

+----------------+
| Key            |
|----------------|
|   frequency    |
| row percentage |
+----------------+

next_event |      out_D_sn_d
      _gap |         0          1 |     Total
-----------+----------------------+----------
         1 |       155          1 |       156 
           |     99.36       0.64 |    100.00 
-----------+----------------------+----------
         2 |       141          3 |       144 
           |     97.92       2.08 |    100.00 
-----------+----------------------+----------
         3 |       100          0 |       100 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         4 |        68          3 |        71 
           |     95.77       4.23 |    100.00 
-----------+----------------------+----------
         5 |        83          3 |        86 
           |     96.51       3.49 |    100.00 
-----------+----------------------+----------
         6 |        91          0 |        91 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         7 |        90          0 |        90 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         8 |        95          0 |        95 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         9 |        66          9 |        75 
           |     88.00      12.00 |    100.00 
-----------+----------------------+----------
        10 |        94          4 |        98 
           |     95.92       4.08 |    100.00 
-----------+----------------------+----------
        11 |        53          1 |        54 
           |     98.15       1.85 |    100.00 
-----------+----------------------+----------
        12 |        50          0 |        50 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        13 |        17          0 |        17 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        14 |        29          0 |        29 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        15 |        13          0 |        13 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        16 |         6          0 |         6 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         . |     6,737        100 |     6,837 
           |     98.54       1.46 |    100.00 
-----------+----------------------+----------
     Total |     7,888        124 |     8,012 
           |     98.45       1.55 |    100.00 

+----------------+
| Key            |
|----------------|
|   frequency    |
| row percentage |
+----------------+

           |      out_D_sn_d
 D_surface |         0          1 |     Total
-----------+----------------------+----------
     Other |       659         44 |       703 
           |     93.74       6.26 |    100.00 
-----------+----------------------+----------
  Flexible |     2,738          1 |     2,739 
           |     99.96       0.04 |    100.00 
-----------+----------------------+----------
     Rigid |     1,348          7 |     1,355 
           |     99.48       0.52 |    100.00 
-----------+----------------------+----------
  Rig/Comp |       756         66 |       822 
           |     91.97       8.03 |    100.00 
-----------+----------------------+----------
 Composite |     2,387          6 |     2,393 
           |     99.75       0.25 |    100.00 
-----------+----------------------+----------
     Total |     7,888        124 |     8,012 
           |     98.45       1.55 |    100.00 

+----------------+
| Key            |
|----------------|
|   frequency    |
| row percentage |
+----------------+

 State IRS |      out_D_sn_d
      code |         0          1 |     Total
-----------+----------------------+----------
         1 |        45          0 |        45 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         3 |       394          0 |       394 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         4 |        34          7 |        41 
           |     82.93      17.07 |    100.00 
-----------+----------------------+----------
         5 |       240          0 |       240 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         6 |       101          0 |       101 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         7 |       182          6 |       188 
           |     96.81       3.19 |    100.00 
-----------+----------------------+----------
         8 |        20          0 |        20 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        10 |       251          2 |       253 
           |     99.21       0.79 |    100.00 
-----------+----------------------+----------
        11 |       163          0 |       163 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        13 |       155          2 |       157 
           |     98.73       1.27 |    100.00 
-----------+----------------------+----------
        14 |       160          3 |       163 
           |     98.16       1.84 |    100.00 
-----------+----------------------+----------
        16 |       111          4 |       115 
           |     96.52       3.48 |    100.00 
-----------+----------------------+----------
        17 |       141          3 |       144 
           |     97.92       2.08 |    100.00 
-----------+----------------------+----------
        18 |       193          3 |       196 
           |     98.47       1.53 |    100.00 
-----------+----------------------+----------
        19 |        89          4 |        93 
           |     95.70       4.30 |    100.00 
-----------+----------------------+----------
        20 |        67          0 |        67 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        21 |       152          2 |       154 
           |     98.70       1.30 |    100.00 
-----------+----------------------+----------
        22 |        72          0 |        72 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        23 |       171          9 |       180 
           |     95.00       5.00 |    100.00 
-----------+----------------------+----------
        24 |        78          9 |        87 
           |     89.66      10.34 |    100.00 
-----------+----------------------+----------
        25 |        25          0 |        25 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        26 |       100          3 |       103 
           |     97.09       2.91 |    100.00 
-----------+----------------------+----------
        27 |       218          0 |       218 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        28 |        92          2 |        94 
           |     97.87       2.13 |    100.00 
-----------+----------------------+----------
        29 |        60          0 |        60 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        30 |       104          0 |       104 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        31 |        79          0 |        79 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        32 |       102          0 |       102 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        33 |       237          0 |       237 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        34 |       165          0 |       165 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        35 |        63          0 |        63 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        36 |       486          9 |       495 
           |     98.18       1.82 |    100.00 
-----------+----------------------+----------
        37 |        33          0 |        33 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        38 |       207          5 |       212 
           |     97.64       2.36 |    100.00 
-----------+----------------------+----------
        39 |     1,630         32 |     1,662 
           |     98.07       1.93 |    100.00 
-----------+----------------------+----------
        40 |        30          0 |        30 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        41 |        26          0 |        26 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        42 |        91          4 |        95 
           |     95.79       4.21 |    100.00 
-----------+----------------------+----------
        43 |       104          0 |       104 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        44 |       266          9 |       275 
           |     96.73       3.27 |    100.00 
-----------+----------------------+----------
        45 |        46          0 |        46 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        46 |        78          0 |        78 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        47 |       120          0 |       120 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        48 |        94          0 |        94 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        49 |       451          0 |       451 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        50 |       110          6 |       116 
           |     94.83       5.17 |    100.00 
-----------+----------------------+----------
        51 |        52          0 |        52 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
     Total |     7,888        124 |     8,012 
           |     98.45       1.55 |    100.00 

+----------------+
| Key            |
|----------------|
|   frequency    |
| row percentage |
+----------------+

Dummy=1 if |      out_D_sn_d
     urban |         0          1 |     Total
-----------+----------------------+----------
         0 |     4,160         52 |     4,212 
           |     98.77       1.23 |    100.00 
-----------+----------------------+----------
         1 |     3,728         72 |     3,800 
           |     98.11       1.89 |    100.00 
-----------+----------------------+----------
     Total |     7,888        124 |     8,012 
           |     98.45       1.55 |    100.00 

+----------------+
| Key            |
|----------------|
|   frequency    |
| row percentage |
+----------------+

           |      out_D_sn_d
event_year |         0          1 |     Total
-----------+----------------------+----------
      1992 |       489          0 |       489 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
      1993 |       369          2 |       371 
           |     99.46       0.54 |    100.00 
-----------+----------------------+----------
      1994 |       579          9 |       588 
           |     98.47       1.53 |    100.00 
-----------+----------------------+----------
      1995 |       573          1 |       574 
           |     99.83       0.17 |    100.00 
-----------+----------------------+----------
      1996 |       534          5 |       539 
           |     99.07       0.93 |    100.00 
-----------+----------------------+----------
      1997 |       463         26 |       489 
           |     94.68       5.32 |    100.00 
-----------+----------------------+----------
      1998 |       622          6 |       628 
           |     99.04       0.96 |    100.00 
-----------+----------------------+----------
      1999 |       480          9 |       489 
           |     98.16       1.84 |    100.00 
-----------+----------------------+----------
      2000 |       550          6 |       556 
           |     98.92       1.08 |    100.00 
-----------+----------------------+----------
      2001 |       570          5 |       575 
           |     99.13       0.87 |    100.00 
-----------+----------------------+----------
      2002 |       297          5 |       302 
           |     98.34       1.66 |    100.00 
-----------+----------------------+----------
      2003 |       433         14 |       447 
           |     96.87       3.13 |    100.00 
-----------+----------------------+----------
      2004 |       368          3 |       371 
           |     99.19       0.81 |    100.00 
-----------+----------------------+----------
      2005 |       313          3 |       316 
           |     99.05       0.95 |    100.00 
-----------+----------------------+----------
      2006 |       345         12 |       357 
           |     96.64       3.36 |    100.00 
-----------+----------------------+----------
      2007 |       387         14 |       401 
           |     96.51       3.49 |    100.00 
-----------+----------------------+----------
      2008 |       516          4 |       520 
           |     99.23       0.77 |    100.00 
-----------+----------------------+----------
     Total |     7,888        124 |     8,012 
           |     98.45       1.55 |    100.00 

+----------------+
| Key            |
|----------------|
|   frequency    |
| row percentage |
+----------------+

multiple_e |      out_D_sn_d
     vents |         0          1 |     Total
-----------+----------------------+----------
         0 |     5,699         86 |     5,785 
           |     98.51       1.49 |    100.00 
-----------+----------------------+----------
         1 |     2,189         38 |     2,227 
           |     98.29       1.71 |    100.00 
-----------+----------------------+----------
     Total |     7,888        124 |     8,012 
           |     98.45       1.55 |    100.00 

+----------------+
| Key            |
|----------------|
|   frequency    |
| row percentage |
+----------------+

next_event |      out_D_sn_d
      _gap |         0          1 |     Total
-----------+----------------------+----------
         1 |       155          1 |       156 
           |     99.36       0.64 |    100.00 
-----------+----------------------+----------
         2 |       141          3 |       144 
           |     97.92       2.08 |    100.00 
-----------+----------------------+----------
         3 |       100          0 |       100 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         4 |        68          3 |        71 
           |     95.77       4.23 |    100.00 
-----------+----------------------+----------
         5 |        83          3 |        86 
           |     96.51       3.49 |    100.00 
-----------+----------------------+----------
         6 |        91          0 |        91 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         7 |        90          0 |        90 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         8 |        95          0 |        95 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         9 |        66          9 |        75 
           |     88.00      12.00 |    100.00 
-----------+----------------------+----------
        10 |        94          4 |        98 
           |     95.92       4.08 |    100.00 
-----------+----------------------+----------
        11 |        53          1 |        54 
           |     98.15       1.85 |    100.00 
-----------+----------------------+----------
        12 |        50          0 |        50 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        13 |        17          0 |        17 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        14 |        29          0 |        29 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        15 |        13          0 |        13 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
        16 |         6          0 |         6 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         . |     6,737        100 |     6,837 
           |     98.54       1.46 |    100.00 
-----------+----------------------+----------
     Total |     7,888        124 |     8,012 
           |     98.45       1.55 |    100.00 

.         keep  if time>-6 &  time<6;
(32,838 observations deleted)

.         drop if next_event_gap<=4 | last_year<=1994;
(3,969 observations deleted)

.         drop if lenght<=4;
(20,130 observations deleted)

.         keep if D_surface==44;
(23,144 observations deleted)

.         tab time, gen(Dum_time) ;

       time |      Freq.     Percent        Cum.
------------+-----------------------------------
         -5 |        450        4.12        4.12
         -4 |        505        4.62        8.74
         -3 |        595        5.45       14.19
         -2 |        797        7.29       21.48
         -1 |        977        8.94       30.42
          0 |      1,335       12.22       42.64
          1 |      1,281       11.72       54.36
          2 |      1,265       11.58       65.94
          3 |      1,214       11.11       77.05
          4 |      1,246       11.40       88.45
          5 |      1,262       11.55      100.00
------------+-----------------------------------
      Total |     10,927      100.00

.         gen D_time=time+5;

.         labmask D_time, values(time);

.         tab D_time, m;

     D_time |      Freq.     Percent        Cum.
------------+-----------------------------------
         -5 |        450        4.12        4.12
         -4 |        505        4.62        8.74
         -3 |        595        5.45       14.19
         -2 |        797        7.29       21.48
         -1 |        977        8.94       30.42
          0 |      1,335       12.22       42.64
          1 |      1,281       11.72       54.36
          2 |      1,265       11.58       65.94
          3 |      1,214       11.11       77.05
          4 |      1,246       11.40       88.45
          5 |      1,262       11.55      100.00
------------+-----------------------------------
      Total |     10,927      100.00

.                 global time_dummies ;

.         foreach var in sn_d iri{;
  2.                 reg `var' ib4.D_time,  robust cluster(id)  ;
  3.                 parmest,format(label estimate  min95 max95 %8.2f p %8.1e) list(,) label saving("temp_`
> var'_vs_time.dta", replace );
  4.         };

Linear regression                               Number of obs     =     10,927
                                                F(10, 1579)       =      20.75
                                                Prob > F          =     0.0000
                                                R-squared         =     0.0142
                                                Root MSE          =      1.171

                                 (Std. err. adjusted for 1,580 clusters in id)
------------------------------------------------------------------------------
             |               Robust
        sn_d | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
      D_time |
         -5  |    .122766   .0475921     2.58   0.010     .0294157    .2161163
         -4  |   .0639017   .0427231     1.50   0.135    -.0198984    .1477017
         -3  |  -.0253177    .037508    -0.67   0.500    -.0988885     .048253
         -2  |  -.1417736   .0265318    -5.34   0.000    -.1938149   -.0897324
          0  |   .1846758   .0247646     7.46   0.000     .1361008    .2332508
          1  |   .2668936   .0286037     9.33   0.000     .2107884    .3229988
          2  |   .2656673   .0279253     9.51   0.000     .2108927    .3204419
          3  |   .2077873   .0320335     6.49   0.000     .1449547      .27062
          4  |   .3130323   .0321361     9.74   0.000     .2499984    .3760662
          5  |   .3260819   .0309692    10.53   0.000     .2653368    .3868271
             |
       _cons |   5.172382   .0380415   135.97   0.000     5.097765    5.246999
------------------------------------------------------------------------------

     +------------------------------------------------------------------------------------------+
  1. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  0.D_time |          |  .12276598 | .04759206 | 1579 |  2.5795472 | 1.0e-02 |  .02941569 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .21611627                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  2. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  1.D_time |          |  .06390166 | .04272314 | 1579 |  1.4957153 | 1.3e-01 |  -.0198984 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .14770171                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  3. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  2.D_time |          | -.02531775 |   .037508 | 1579 | -.67499589 | 5.0e-01 | -.09888847 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .04825298                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  4. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  3.D_time |          | -.14177364 |  .0265318 | 1579 | -5.3435373 | 1.0e-07 | -.19381489 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                        -.08973238                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  5. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     | 4b.D_time |          |          0 |         0 | 1579 |          . |       . |          0 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                                 0                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  6. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  5.D_time |          |  .18467579 | .02476462 | 1579 |  7.4572442 | 1.5e-13 |   .1361008 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .23325078                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  7. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  6.D_time |          |  .26689357 | .02860368 | 1579 |  9.3307421 | 3.4e-20 |  .21078838 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .32299876                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  8. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  7.D_time |          |  .26566733 | .02792531 | 1579 |  9.5134972 | 6.6e-21 |  .21089275 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .32044191                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  9. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  8.D_time |          |  .20778735 | .03203349 | 1579 |  6.4865667 | 1.2e-10 |   .1449547 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .27061999                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
 10. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  9.D_time |          |   .3130323 | .03213609 | 1579 |   9.740834 | 8.2e-22 |  .24999841 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .37606619                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
 11. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     | 10.D_time |          |  .32608191 | .03096924 | 1579 |  10.529219 | 4.2e-25 |  .26533675 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .38682706                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
 12. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |     _cons | Constant |  5.1723822 | .03804147 | 1579 |  135.96694 | 0.0e+00 |  5.0977651 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         5.2469993                                        |
     +------------------------------------------------------------------------------------------+
(file temp_sn_d_vs_time.dta not found)
file temp_sn_d_vs_time.dta saved

Linear regression                               Number of obs     =     10,927
                                                F(10, 1579)       =      65.05
                                                Prob > F          =     0.0000
                                                R-squared         =     0.0906
                                                Root MSE          =     30.099

                                 (Std. err. adjusted for 1,580 clusters in id)
------------------------------------------------------------------------------
             |               Robust
         iri | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
      D_time |
         -5  |   -2.81934   1.680575    -1.68   0.094    -6.115732    .4770528
         -4  |  -.1098804   1.602376    -0.07   0.945    -3.252889    3.033128
         -3  |  -.5198546   1.484472    -0.35   0.726    -3.431599     2.39189
         -2  |  -.3882294   1.157924    -0.34   0.737    -2.659459       1.883
          0  |  -20.61791   1.130662   -18.24   0.000    -22.83567   -18.40016
          1  |  -17.41489    1.25738   -13.85   0.000     -19.8812   -14.94858
          2  |   -21.3183   1.267215   -16.82   0.000     -23.8039    -18.8327
          3  |   -22.4676   1.231506   -18.24   0.000    -24.88315   -20.05204
          4  |  -22.30161   1.208827   -18.45   0.000    -24.67268   -19.93053
          5  |  -21.79326   1.237704   -17.61   0.000    -24.22098   -19.36554
             |
       _cons |   93.79915   1.190507    78.79   0.000     91.46401    96.13429
------------------------------------------------------------------------------

     +------------------------------------------------------------------------------------------+
  1. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  0.D_time |          | -2.8193396 | 1.6805745 | 1579 | -1.6776046 | 9.4e-02 | -6.1157319 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         .47705277                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  2. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  1.D_time |          | -.10988045 | 1.6023758 | 1579 | -.06857346 | 9.5e-01 | -3.2528885 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         3.0331276                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  3. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  2.D_time |          | -.51985465 | 1.4844724 | 1579 | -.35019489 | 7.3e-01 |  -3.431599 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         2.3918897                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  4. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  3.D_time |          | -.38822944 | 1.1579237 | 1579 | -.33528067 | 7.4e-01 | -2.6594592 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         1.8830004                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  5. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     | 4b.D_time |          |          0 |         0 | 1579 |          . |       . |          0 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                                 0                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  6. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  5.D_time |          | -20.617915 | 1.1306624 | 1579 | -18.235252 | 1.4e-67 | -22.835672 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                        -18.400157                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  7. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  6.D_time |          | -17.414894 | 1.2573798 | 1579 | -13.850146 | 3.0e-41 | -19.881203 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                        -14.948584                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  8. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  7.D_time |          | -21.318298 | 1.2672149 | 1579 | -16.822953 | 1.5e-58 | -23.803899 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                        -18.832697                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
  9. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  8.D_time |          | -22.467595 | 1.2315062 | 1579 | -18.243996 | 1.3e-67 | -24.883155 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                        -20.052036                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
 10. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |  9.D_time |          | -22.301606 | 1.2088272 | 1579 | -18.448961 | 5.6e-69 | -24.672681 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                        -19.930531                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
 11. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     | 10.D_time |          | -21.793259 |  1.237704 | 1579 | -17.607811 | 1.7e-63 | -24.220975 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                        -19.365543                                        |
     +------------------------------------------------------------------------------------------+

     +------------------------------------------------------------------------------------------+
 12. |      parm |    label |   estimate |    stderr |  dof |          t |       p |      min95 |
     |     _cons | Constant |  93.799154 | 1.1905068 | 1579 |  78.789265 | 0.0e+00 |  91.464014 |
     |------------------------------------------------------------------------------------------|
     |                                             max95                                        |
     |                                         96.134295                                        |
     +------------------------------------------------------------------------------------------+
(file temp_iri_vs_time.dta not found)
file temp_iri_vs_time.dta saved

.                 *Figure ;
.                                                 use "temp_sn_d_vs_time.dta", clear;

.                                                 gen var= "sn_dD";

.                                                 append using "temp_iri_vs_time.dta";

.                                                 replace var="iri" if var=="";
(12 real changes made)

.                         drop if label=="State IRS code";
(0 observations deleted)

.                         gen time=subinstr(parm, ".D_time","", .);

.                         replace time="4"  if time=="4b";
(2 real changes made)

.                         destring time, replace force;
time: contains nonnumeric characters; replaced as byte
(2 missing values generated)

.                         keep parm time  estimate min max var;

.                         drop if time==.;
(2 observations deleted)

.                         replace time=time-5;
(22 real changes made)

.                         reshape wide estimate min max,i(time) j(var) string;
(j = iri sn_dD)

Data                               Long   ->   Wide
-----------------------------------------------------------------------------
Number of observations               22   ->   11          
Number of variables                   6   ->   8           
j variable (2 values)               var   ->   (dropped)
xij variables:
                               estimate   ->   estimateiri estimatesn_dD
                                  min95   ->   min95iri min95sn_dD
                                  max95   ->   max95iri max95sn_dD
-----------------------------------------------------------------------------

.                         ren estimate* *;

.                         label var iri "IRI";

.                         label var sn_d "SN/D";

.                         label var       min95iri "95% CI" ;

.                         label var  max95iri "95% CI" ;

.                         label var min95sn_d "95% CI" ;

.                         label var max95sn_d "95% CI"  ;

.                         tw 
>                            (rarea min95iri max95iri time  ,msize(*0.6) color(%30))  
>                            (rarea min95sn_d max95sn_d time ,msize(*0.6) yaxis(2)   color(%20))
>                            (con iri  time ,msize(*0.6))  
>                            (con sn_d time ,msize(*0.6) yaxis(2)  lp(longdash) )
>                           , 
>                           ytitle("IRI") ytitle( "SN/D",axis(2) )
>                                    legend( off
>                                    order(2 4 1)
>                                    pos(2) col(2) ring(0))
>                                    xlabel(-5(1)5)
>                                    xtitle("")
>                                         xline(0, lp(dot) lc(gs8))
>                                         scale(*1.3)
>                                         xmtick(##5)
>                                         ymtick(##4)
>                                    ;
(note:  named style med not found in class gsize, default attributes used)

.                                    pause ;

.                                    graph export "${output}/Figures/FigureB2_events.pdf", replace ;
file /Users/juanpablouribetrujillo/My Drive
    (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analysis/..//Figures/FigureB2_events.pdf saved as
    PDF format

.                         erase "temp_sn_d_vs_time.dta";

.         erase "temp_iri_vs_time.dta";

. 
end of do-file
.         };

. * Appendix Figure B3;
. if 1==1{;
.         do "universe_maint.do";

. 
. 
. # delim ;  
delimiter now ;
. clear all;

. set matsize 11000 ;
set matsize ignored.
    Matrix sizes are no longer limited by c(matsize) in modern Statas.  Matrix sizes are now limited by
    edition of Stata.  See limits for more details.

. eststo clear ;

. capture program drop add_lab_FE;

. capture log close ;
